/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  
  checkConfig(config);
  @endpoint = getEndpoint('xtrace', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CheckCommercialStatusRequest {
  regionId?: string(name='RegionId', example='cn-beijing'),
  service?: string(name='Service', description='The service code.

This parameter is required.', example='xtrace'),
}

model CheckCommercialStatusResponseBody = {
  data?: string(name='Data', example='true'),
  requestId?: string(name='RequestId', description='Id of the request', example='1E2B6A4C-6B83-4062-8B6F-AEEC1FC47DED'),
}

model CheckCommercialStatusResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: CheckCommercialStatusResponseBody(name='body'),
}

/**
 * @summary 检查商业化状态
 *
 * @param request CheckCommercialStatusRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return CheckCommercialStatusResponse
 */
async function checkCommercialStatusWithOptions(request: CheckCommercialStatusRequest, runtime: Util.RuntimeOptions): CheckCommercialStatusResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.regionId)) {
    query['RegionId'] = request.regionId;
  }
  if (!Util.isUnset(request.service)) {
    query['Service'] = request.service;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'CheckCommercialStatus',
    version = '2019-08-08',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary 检查商业化状态
 *
 * @param request CheckCommercialStatusRequest
 * @return CheckCommercialStatusResponse
 */
async function checkCommercialStatus(request: CheckCommercialStatusRequest): CheckCommercialStatusResponse {
  var runtime = new Util.RuntimeOptions{};
  return checkCommercialStatusWithOptions(request, runtime);
}

model GetTagKeyRequest {
  endTime?: long(name='EndTime', description='The end of the time range to query. The value is a timestamp that is accurate to milliseconds.

>  The value of this parameter is of the LONG type. Precision loss may occur during serialization or deserialization. The value must be less than or equal to 9007199254740991.', example='1575622455686'),
  regionId?: string(name='RegionId', description='The ID of the region.

This parameter is required.', example='cn-beijing'),
  serviceName?: string(name='ServiceName', description='The name of the application.', example='appTest'),
  spanName?: string(name='SpanName', description='The name of the span.', example='createOrder'),
  startTime?: long(name='StartTime', description='The beginning of the time range to query. The value is a timestamp that is accurate to milliseconds.

>  The value of this parameter is of the LONG type. Precision loss may occur during serialization or deserialization. The value must be less than or equal to 9007199254740991.', example='1575561600000'),
}

model GetTagKeyResponseBody = {
  requestId?: string(name='RequestId', description='The ID of the request.', example='1E2B6A4C-6B83-4062-8B6F-AEEC1F******'),
  tagKeys?: {
    tagKey?: [ string ](name='TagKey')
  }(name='TagKeys', description='The tag keys.'),
}

model GetTagKeyResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetTagKeyResponseBody(name='body'),
}

/**
 * @summary Queries tag keys.
 *
 * @param request GetTagKeyRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetTagKeyResponse
 */
async function getTagKeyWithOptions(request: GetTagKeyRequest, runtime: Util.RuntimeOptions): GetTagKeyResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.endTime)) {
    query['EndTime'] = request.endTime;
  }
  if (!Util.isUnset(request.regionId)) {
    query['RegionId'] = request.regionId;
  }
  if (!Util.isUnset(request.serviceName)) {
    query['ServiceName'] = request.serviceName;
  }
  if (!Util.isUnset(request.spanName)) {
    query['SpanName'] = request.spanName;
  }
  if (!Util.isUnset(request.startTime)) {
    query['StartTime'] = request.startTime;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetTagKey',
    version = '2019-08-08',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary Queries tag keys.
 *
 * @param request GetTagKeyRequest
 * @return GetTagKeyResponse
 */
async function getTagKey(request: GetTagKeyRequest): GetTagKeyResponse {
  var runtime = new Util.RuntimeOptions{};
  return getTagKeyWithOptions(request, runtime);
}

model GetTagValRequest {
  endTime?: long(name='EndTime', description='The end of the time range to query. The value is a timestamp that is accurate to milliseconds.

>  This value is of the LONG type, and precision loss may occur during serialization or deserialization. Do not set this parameter to a value greater than 9007199254740991.', example='1575622455686'),
  regionId?: string(name='RegionId', description='The ID of the region.', example='cn-beijing'),
  serviceName?: string(name='ServiceName', description='The name of the application.', example='appTest'),
  spanName?: string(name='SpanName', description='The name of the span.', example='createOrder'),
  startTime?: long(name='StartTime', description='The beginning of the time range to query. The value is a timestamp that is accurate to milliseconds.

>  This value is of the LONG type, and precision loss may occur during serialization or deserialization. Do not set this parameter to a value greater than 9007199254740991.', example='1575561600000'),
  tagKey?: string(name='TagKey', description='The tag key.

You can call the [GetTagKey](https://help.aliyun.com/document_detail/2399667.html) operation to obtain a tag key.

This parameter is required.', example='span.kind'),
}

model GetTagValResponseBody = {
  requestId?: string(name='RequestId', description='The ID of the request.', example='1E2B6A4C-6B83-4062-8B6F-AEEC1F******'),
  tagValues?: {
    tagValue?: [ string ](name='TagValue')
  }(name='TagValues', description='The tag values.'),
}

model GetTagValResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetTagValResponseBody(name='body'),
}

/**
 * @summary Queries the tag values that correspond to a tag key.
 *
 * @param request GetTagValRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetTagValResponse
 */
async function getTagValWithOptions(request: GetTagValRequest, runtime: Util.RuntimeOptions): GetTagValResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.endTime)) {
    query['EndTime'] = request.endTime;
  }
  if (!Util.isUnset(request.regionId)) {
    query['RegionId'] = request.regionId;
  }
  if (!Util.isUnset(request.serviceName)) {
    query['ServiceName'] = request.serviceName;
  }
  if (!Util.isUnset(request.spanName)) {
    query['SpanName'] = request.spanName;
  }
  if (!Util.isUnset(request.startTime)) {
    query['StartTime'] = request.startTime;
  }
  if (!Util.isUnset(request.tagKey)) {
    query['TagKey'] = request.tagKey;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetTagVal',
    version = '2019-08-08',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary Queries the tag values that correspond to a tag key.
 *
 * @param request GetTagValRequest
 * @return GetTagValResponse
 */
async function getTagVal(request: GetTagValRequest): GetTagValResponse {
  var runtime = new Util.RuntimeOptions{};
  return getTagValWithOptions(request, runtime);
}

model GetTraceRequest {
  appType?: string(name='AppType', description='The type of the application. You can leave this parameter empty or set this parameter to `XTRACE`. We recommend that you leave this parameter empty.

*   If you leave this parameter empty, traces reported to Managed Service for OpenTelemetry and Application Real-Time Monitoring Service (ARMS) can be queried.
*   If you set this parameter to `XTRACE`, only traces reported to Managed Service for OpenTelemetry can be queried.', example='XTRACE'),
  pageNumber?: long(name='PageNumber'),
  pageSize?: string(name='PageSize'),
  regionId?: string(name='RegionId', description='The ID of the region.

This parameter is required.', example='cn-beijing'),
  traceID?: string(name='TraceID', description='The trace ID, which is the unique identifier of the trace.

You can obtain the trace ID on the **Trace Explorer** page in the Managed Service for OpenTelemetry console or by calling the [SearchTraces](https://help.aliyun.com/document_detail/2399674.html~) operation.

This parameter is required.', example='1c6881aab84191a4'),
}

model GetTraceResponseBody = {
  requestId?: string(name='RequestId', description='The ID of the request.', example='1E2B6A4C-6B83-4062-8B6F-AEEC1F******'),
  spans?: {
    span?: [ 
    {
      duration?: long(name='Duration', description='The duration of the span. Unit: milliseconds.', example='1000'),
      haveStack?: boolean(name='HaveStack', description='Indicates whether the span has child spans. Valid values:

*   `true`
*   `false`', example='false'),
      logEventList?: {
        logEvent?: [ 
        {
          tagEntryList?: {
            tagEntry?: [ 
            {
              key?: string(name='Key', description='The tag key of the log event.', example='logLevel'),
              value?: string(name='Value', description='The tag value of the log event.', example='Warning'),
            }
          ](name='TagEntry')
          }(name='TagEntryList', description='The tags.'),
          timestamp?: long(name='Timestamp', description='The timestamp when the log event was generated. Unit: microseconds.', example='1583683202047000'),
        }
      ](name='LogEvent')
      }(name='LogEventList', description='The log events.'),
      operationName?: string(name='OperationName', description='The name of the span.', example='/api'),
      parentSpanId?: string(name='ParentSpanId', description='The ID of the parent span.', example='fec891bb8f8XXX'),
      resultCode?: string(name='ResultCode', description='The response code.', example='200'),
      rpcId?: string(name='RpcId', description='The parent-child and sibling relationship between spans. For example, span 1.1 is the parent of span 1.1.1, and span 1.1.2 and span 1.1.1 are siblings.', example='1.1'),
      serviceIp?: string(name='ServiceIp', description='The IP address of the server on which the span resides.', example='192.168.XXX.XXX'),
      serviceName?: string(name='ServiceName', description='The name of the application.', example='server1'),
      spanId?: string(name='SpanId', description='The span ID.', example='fec891bb8f8XXX'),
      statusCode?: long(name='StatusCode'),
      tagEntryList?: {
        tagEntry?: [ 
        {
          key?: string(name='Key', description='The tag key of the span.', example='logLevel'),
          value?: string(name='Value', description='The tag value of the span.', example='Warning'),
        }
      ](name='TagEntry')
      }(name='TagEntryList', description='The tags.'),
      timestamp?: long(name='Timestamp', description='The timestamp when the span was generated. Unit: microseconds.', example='1689845513298000'),
      traceID?: string(name='TraceID', description='The trace ID, which is the unique identifier of the trace.', example='1c6881aab84191a4****'),
    }
  ](name='Span')
  }(name='Spans', description='The spans that are contained in the trace.'),
}

model GetTraceResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetTraceResponseBody(name='body'),
}

/**
 * @summary Queries the details of a trace.
 *
 * @param request GetTraceRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetTraceResponse
 */
async function getTraceWithOptions(request: GetTraceRequest, runtime: Util.RuntimeOptions): GetTraceResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.appType)) {
    query['AppType'] = request.appType;
  }
  if (!Util.isUnset(request.pageNumber)) {
    query['PageNumber'] = request.pageNumber;
  }
  if (!Util.isUnset(request.pageSize)) {
    query['PageSize'] = request.pageSize;
  }
  if (!Util.isUnset(request.regionId)) {
    query['RegionId'] = request.regionId;
  }
  if (!Util.isUnset(request.traceID)) {
    query['TraceID'] = request.traceID;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetTrace',
    version = '2019-08-08',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary Queries the details of a trace.
 *
 * @param request GetTraceRequest
 * @return GetTraceResponse
 */
async function getTrace(request: GetTraceRequest): GetTraceResponse {
  var runtime = new Util.RuntimeOptions{};
  return getTraceWithOptions(request, runtime);
}

model ListIpOrHostsRequest {
  endTime?: long(name='EndTime', description='The end of the time range to query. The value is a timestamp that is accurate to milliseconds.', example='1583723776974'),
  regionId?: string(name='RegionId', description='The region ID.

This parameter is required.', example='cn-beijing'),
  serviceName?: string(name='ServiceName', description='The name of the service. If you do not specify this parameter, the IP addresses of all applications in the specified region are returned.', example='service1'),
  startTime?: long(name='StartTime', description='The beginning of the time range to query. The value is a timestamp that is accurate to milliseconds.', example='1583683200000'),
}

model ListIpOrHostsResponseBody = {
  ipNames?: {
    ipName?: [ string ](name='IpName')
  }(name='IpNames', description='The IP addresses.'),
  requestId?: string(name='RequestId', description='The request ID.', example='1E2B6A4C-6B83-4062-8B6F-AEEC1FC4****'),
}

model ListIpOrHostsResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListIpOrHostsResponseBody(name='body'),
}

/**
 * @summary Queries IP addresses or hostnames in trace data. You can obtain all IP addresses of an application or in a region.
 *
 * @param request ListIpOrHostsRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ListIpOrHostsResponse
 */
async function listIpOrHostsWithOptions(request: ListIpOrHostsRequest, runtime: Util.RuntimeOptions): ListIpOrHostsResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.endTime)) {
    query['EndTime'] = request.endTime;
  }
  if (!Util.isUnset(request.regionId)) {
    query['RegionId'] = request.regionId;
  }
  if (!Util.isUnset(request.serviceName)) {
    query['ServiceName'] = request.serviceName;
  }
  if (!Util.isUnset(request.startTime)) {
    query['StartTime'] = request.startTime;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListIpOrHosts',
    version = '2019-08-08',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary Queries IP addresses or hostnames in trace data. You can obtain all IP addresses of an application or in a region.
 *
 * @param request ListIpOrHostsRequest
 * @return ListIpOrHostsResponse
 */
async function listIpOrHosts(request: ListIpOrHostsRequest): ListIpOrHostsResponse {
  var runtime = new Util.RuntimeOptions{};
  return listIpOrHostsWithOptions(request, runtime);
}

model ListServicesRequest {
  appType?: string(name='AppType', description='The type of the application. You can leave this parameter empty or set this parameter to `XTRACE`. We recommend that you leave this parameter empty.

*   If you leave this parameter empty, applications monitored by Managed Service for OpenTelemetry or Application Real-Time Monitoring Service (ARMS) can be queried.
*   If you set this parameter to `XTRACE`, only applications monitored by Managed Service for OpenTelemetry can be queried.', example='XTRACE'),
  regionId?: string(name='RegionId', description='The ID of the region.

This parameter is required.', example='cn-beijing'),
}

model ListServicesResponseBody = {
  requestId?: string(name='RequestId', description='The ID of the region.', example='1E2B6A4C-6B83-4062-8B6F-AEEC1FC47DED'),
  services?: {
    service?: [ 
    {
      pid?: string(name='Pid', description='The ID of the application.', example='XXXqn3ly@741623b4e915df8'),
      regionId?: string(name='RegionId', description='The ID of the region.', example='cn-beijing'),
      serviceName?: string(name='ServiceName', description='The name of the application.', example='a3'),
    }
  ](name='Service')
  }(name='Services', description='The applications.'),
}

model ListServicesResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListServicesResponseBody(name='body'),
}

/**
 * @summary Queries applications.
 *
 * @param request ListServicesRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ListServicesResponse
 */
async function listServicesWithOptions(request: ListServicesRequest, runtime: Util.RuntimeOptions): ListServicesResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.appType)) {
    query['AppType'] = request.appType;
  }
  if (!Util.isUnset(request.regionId)) {
    query['RegionId'] = request.regionId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListServices',
    version = '2019-08-08',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary Queries applications.
 *
 * @param request ListServicesRequest
 * @return ListServicesResponse
 */
async function listServices(request: ListServicesRequest): ListServicesResponse {
  var runtime = new Util.RuntimeOptions{};
  return listServicesWithOptions(request, runtime);
}

model ListSpanNamesRequest {
  endTime?: long(name='EndTime', description='The end of the time range to query. The value is a timestamp that is accurate to milliseconds.', example='1575622455686'),
  regionId?: string(name='RegionId', description='The ID of the region.

This parameter is required.', example='cn-beijing'),
  serviceName?: string(name='ServiceName', description='The name of the application.', example='service 1'),
  startTime?: long(name='StartTime', description='The beginning of the time range to query. The value is a timestamp that is accurate to milliseconds.', example='1575561600000'),
}

model ListSpanNamesResponseBody = {
  requestId?: string(name='RequestId', description='The ID of the request.', example='1E2B6A4C-6B83-4062-8B6F-AEEC1F******'),
  spanNames?: {
    spanName?: [ string ](name='SpanName')
  }(name='SpanNames', description='The span names.'),
}

model ListSpanNamesResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListSpanNamesResponseBody(name='body'),
}

/**
 * @summary Queries all span names in a specified region or all span names of a microservice.
 *
 * @param request ListSpanNamesRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ListSpanNamesResponse
 */
async function listSpanNamesWithOptions(request: ListSpanNamesRequest, runtime: Util.RuntimeOptions): ListSpanNamesResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.endTime)) {
    query['EndTime'] = request.endTime;
  }
  if (!Util.isUnset(request.regionId)) {
    query['RegionId'] = request.regionId;
  }
  if (!Util.isUnset(request.serviceName)) {
    query['ServiceName'] = request.serviceName;
  }
  if (!Util.isUnset(request.startTime)) {
    query['StartTime'] = request.startTime;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListSpanNames',
    version = '2019-08-08',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary Queries all span names in a specified region or all span names of a microservice.
 *
 * @param request ListSpanNamesRequest
 * @return ListSpanNamesResponse
 */
async function listSpanNames(request: ListSpanNamesRequest): ListSpanNamesResponse {
  var runtime = new Util.RuntimeOptions{};
  return listSpanNamesWithOptions(request, runtime);
}

model OpenXtraceServiceRequest {
  regionId?: string(name='RegionId'),
}

model OpenXtraceServiceResponseBody = {
  orderId?: string(name='OrderId', example='155709986'),
  requestId?: string(name='RequestId', example='1E2B6A4C-6B83-4062-8B6F-AEEC1FC4****'),
  result?: string(name='Result'),
}

model OpenXtraceServiceResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: OpenXtraceServiceResponseBody(name='body'),
}

/**
 * @summary Activates Managed Service for OpenTelemetry.
 *
 * @param request OpenXtraceServiceRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return OpenXtraceServiceResponse
 */
async function openXtraceServiceWithOptions(request: OpenXtraceServiceRequest, runtime: Util.RuntimeOptions): OpenXtraceServiceResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.regionId)) {
    query['RegionId'] = request.regionId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'OpenXtraceService',
    version = '2019-08-08',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary Activates Managed Service for OpenTelemetry.
 *
 * @param request OpenXtraceServiceRequest
 * @return OpenXtraceServiceResponse
 */
async function openXtraceService(request: OpenXtraceServiceRequest): OpenXtraceServiceResponse {
  var runtime = new Util.RuntimeOptions{};
  return openXtraceServiceWithOptions(request, runtime);
}

model QueryMetricRequest {
  dimensions?: [ string ](name='Dimensions', description='The dimensions of the metric that you want to query.', example='RT'),
  endTime?: long(name='EndTime', description='The end of the time range to query. The value is a timestamp that is accurate to milliseconds.

>  The value of this parameter is of the LONG type. Precision loss may occur during serialization or deserialization. The value must be less than or equal to 9007199254740991.

This parameter is required.', example='1575622455686'),
  filters?: [ 
    {
      key?: string(name='Key', description='The key of the field that you want to use to filter the returned entries.', example='http.status_code'),
      value?: string(name='Value', description='The value of the field that you want to use to filter the returned entries.', example='200'),
    }
  ](name='Filters', description='The filter conditions.'),
  intervalInSec?: int32(name='IntervalInSec', description='The time interval at which you want to query metric data. Unit: milliseconds. Minimum value: 60000. 

> If you set this parameter to 2147483647, all data in the specified time interval is returned.', example='100000'),
  limit?: int32(name='Limit', description='The maximum number of entries that you want to return.', example='100'),
  measures?: [ string ](name='Measures', description='The measures of the metric that you want to query.

This parameter is required.', example='count'),
  metric?: string(name='Metric', description='The name of the metric. Valid values:

- `appstat.incall`: trace statistics 
- `appstat.sql`: SQL statistics

This parameter is required.', example='appstat.incall'),
  order?: string(name='Order', description='The order in which you want to sort the returned entries. Valid values:

- ASC: ascending order 
- DESC: descending order', example='ASC'),
  orderBy?: string(name='OrderBy', description='The field based on which you want to sort the returned entries.', example='count'),
  proxyUserId?: string(name='ProxyUserId', description='The ID of the proxy user.', example='testefgag12'),
  startTime?: long(name='StartTime', description='The beginning of the time range to query. The value is a timestamp that is accurate to milliseconds.

>  The value of this parameter is of the LONG type. Precision loss may occur during serialization or deserialization. The value must be less than or equal to 9007199254740991.

This parameter is required.', example='1575561600000'),
}

model QueryMetricResponseBody = {
  data?: string(name='Data', description='The returned statistics.', example='{   "RequestId": "E2373982-D8CD-413D-B991-8EB678******",   "Data": "{\\\\"data\\\\":[{\\\\"date\\\\":1583686800000,\\\\"count\\\\":0,\\\\"rt\\\\":0,\\\\"rpc\\\\":\\\\"childSpan3\\\\"}}'),
  requestId?: string(name='RequestId', description='The ID of the request.', example='1E2B6A4C-6B83-4062-8B6F-AEEC1F******'),
}

model QueryMetricResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: QueryMetricResponseBody(name='body'),
}

/**
 * @summary Queries a metric.
 *
 * @param request QueryMetricRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return QueryMetricResponse
 */
async function queryMetricWithOptions(request: QueryMetricRequest, runtime: Util.RuntimeOptions): QueryMetricResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.dimensions)) {
    query['Dimensions'] = request.dimensions;
  }
  if (!Util.isUnset(request.endTime)) {
    query['EndTime'] = request.endTime;
  }
  if (!Util.isUnset(request.filters)) {
    query['Filters'] = request.filters;
  }
  if (!Util.isUnset(request.intervalInSec)) {
    query['IntervalInSec'] = request.intervalInSec;
  }
  if (!Util.isUnset(request.limit)) {
    query['Limit'] = request.limit;
  }
  if (!Util.isUnset(request.measures)) {
    query['Measures'] = request.measures;
  }
  if (!Util.isUnset(request.metric)) {
    query['Metric'] = request.metric;
  }
  if (!Util.isUnset(request.order)) {
    query['Order'] = request.order;
  }
  if (!Util.isUnset(request.orderBy)) {
    query['OrderBy'] = request.orderBy;
  }
  if (!Util.isUnset(request.proxyUserId)) {
    query['ProxyUserId'] = request.proxyUserId;
  }
  if (!Util.isUnset(request.startTime)) {
    query['StartTime'] = request.startTime;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'QueryMetric',
    version = '2019-08-08',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary Queries a metric.
 *
 * @param request QueryMetricRequest
 * @return QueryMetricResponse
 */
async function queryMetric(request: QueryMetricRequest): QueryMetricResponse {
  var runtime = new Util.RuntimeOptions{};
  return queryMetricWithOptions(request, runtime);
}

model SearchTracesRequest {
  appType?: string(name='AppType', description='The type of the application. You can set the value to **XTRACE** or leave this parameter unspecified.', example='XTRACE'),
  endTime?: long(name='EndTime', description='The end of the time range to query. The value is a timestamp that is accurate to milliseconds.

This parameter is required.', example='1575622455686'),
  minDuration?: long(name='MinDuration', description='The minimum value of an execution duration. Unit: seconds. For example, a value of 2 indicates that the traces whose execution duration is more than 2 seconds are queried.', example='1000'),
  operationName?: string(name='OperationName', description='The name of the span.', example='/api'),
  pageNumber?: int32(name='PageNumber', description='The number of the page to return. For example, a value of 5 indicates page 5.', example='1'),
  pageSize?: int32(name='PageSize', description='The number of entries per page.', example='100'),
  regionId?: string(name='RegionId', description='The ID of the region.

This parameter is required.', example='cn-beijing'),
  reverse?: boolean(name='Reverse', description='Specifies whether to sort the query results in chronological order or reverse chronological order. Default value: false. Valid values:

- true: reverse chronological order 
- false: chronological order', example='false'),
  serviceIp?: string(name='ServiceIp', description='The IP address of the server on which the span is running.', example='10.0.0.0'),
  serviceName?: string(name='ServiceName', description='The name of the application.', example='service 1'),
  startTime?: long(name='StartTime', description='The beginning of the time range to query. The value is a timestamp that is accurate to milliseconds.

This parameter is required.', example='1575561600000'),
  statusCode?: string(name='StatusCode'),
  tag?: [ 
    {
      key?: string(name='Key', description='The key of the tag.', example='http.status_cod'),
      value?: string(name='Value', description='The value of the tag.', example='200'),
    }
  ](name='Tag', description='The list of the tags.'),
}

model SearchTracesResponseBody = {
  pageBean?: {
    pageNumber?: int32(name='PageNumber', description='The page number of the returned page.', example='1'),
    pageSize?: int32(name='PageSize', description='The number of entries per page.', example='100'),
    totalCount?: long(name='TotalCount', description='The total number of entries returned.', example='1000'),
    traceInfos?: {
      traceInfo?: [ 
      {
        duration?: long(name='Duration', description='The execution duration. Unit: seconds.', example='100'),
        operationName?: string(name='OperationName', description='The span name.', example='/api'),
        serviceIp?: string(name='ServiceIp', description='The IP address or name of the server on which the span is running.', example='192.163.XXX.XXX'),
        serviceName?: string(name='ServiceName', description='The service name.', example='service1'),
        statusCode?: long(name='StatusCode'),
        tagMap?: map[string]any(name='TagMap', description='The tag information.', example='{"env":"dev"}'),
        timestamp?: long(name='Timestamp', description='The timestamp when the span was generated. Unit: millisecond.', example='1575561600000000'),
        traceID?: string(name='TraceID', description='The trace ID.', example='1c6881aab84191a4'),
      }
    ](name='TraceInfo')
    }(name='TraceInfos', description='The information about the traces that are returned.'),
  }(name='PageBean', description='The information about the returned page.'),
  requestId?: string(name='RequestId', description='The ID of the request.', example='1E2B6A4C-6B83-4062-8B6F-AEEC1F******'),
}

model SearchTracesResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SearchTracesResponseBody(name='body'),
}

/**
 * @summary Queries traces by time, application name, IP address, span name, and tag.
 *
 * @param request SearchTracesRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SearchTracesResponse
 */
async function searchTracesWithOptions(request: SearchTracesRequest, runtime: Util.RuntimeOptions): SearchTracesResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.appType)) {
    query['AppType'] = request.appType;
  }
  if (!Util.isUnset(request.endTime)) {
    query['EndTime'] = request.endTime;
  }
  if (!Util.isUnset(request.minDuration)) {
    query['MinDuration'] = request.minDuration;
  }
  if (!Util.isUnset(request.operationName)) {
    query['OperationName'] = request.operationName;
  }
  if (!Util.isUnset(request.pageNumber)) {
    query['PageNumber'] = request.pageNumber;
  }
  if (!Util.isUnset(request.pageSize)) {
    query['PageSize'] = request.pageSize;
  }
  if (!Util.isUnset(request.regionId)) {
    query['RegionId'] = request.regionId;
  }
  if (!Util.isUnset(request.reverse)) {
    query['Reverse'] = request.reverse;
  }
  if (!Util.isUnset(request.serviceIp)) {
    query['ServiceIp'] = request.serviceIp;
  }
  if (!Util.isUnset(request.serviceName)) {
    query['ServiceName'] = request.serviceName;
  }
  if (!Util.isUnset(request.startTime)) {
    query['StartTime'] = request.startTime;
  }
  if (!Util.isUnset(request.statusCode)) {
    query['StatusCode'] = request.statusCode;
  }
  if (!Util.isUnset(request.tag)) {
    query['Tag'] = request.tag;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SearchTraces',
    version = '2019-08-08',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary Queries traces by time, application name, IP address, span name, and tag.
 *
 * @param request SearchTracesRequest
 * @return SearchTracesResponse
 */
async function searchTraces(request: SearchTracesRequest): SearchTracesResponse {
  var runtime = new Util.RuntimeOptions{};
  return searchTracesWithOptions(request, runtime);
}

